package xyf.p11.other.slidewindow;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: J057_Insert
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:18 AM
 * Version: 1.0
 **/
public class J057_Insert
{
    public int[][] findContinuousSequence(int target)
    {
        List<List<Integer>> res = new ArrayList<>();
        int fast = 1;
        int slow = 1;
        int sum = 0;
        while (fast < target)
        {
            if (sum > target)
            {
                sum -= slow;
                slow++;
            }
            else if (sum == target)
            {
                List<Integer> tmp = new ArrayList<>();
                for (int i = slow; i < fast; i++)
                {
                    tmp.add(i);
                }
                res.add(tmp);
                sum -= slow;
                slow++;
            }
            else
            {
                sum += fast;
                fast++;
            }
        }

        int[][] result = new int[res.size()][];
        for (int i = 0; i < res.size(); i++)
        {
            int[] arr = res.get(i).stream().mapToInt(Integer::intValue).toArray();
            result[i] = arr;
        }
        return result;
    }
}
